package com.sise.wangzhan.controller;

import lombok.Data;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;


/**
 * @Classname PersonController
 * @Description TODO
 * @Date 2020/4/8 20:22
 * @Created by wangzhan
 */
@RestController
public class PersonController {

    //produces：指定返回内容类型
    @RequestMapping(value = "/person/{person_id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
    public Person findPerson(@PathVariable ("person_id") Integer person_id, HttpServletRequest request){
        Person person = new Person();
        person.setPerson_id(person_id);
        person.setP_name("wangzhan");
        person.setAge(22);
        person.setMessage(request.getRequestURL().toString());

        return person;
    }

    //consume：指定请求内容类型
    @RequestMapping(value = "/person/create",method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
    public String createPerson(@RequestBody Person person){
        System.out.println(person.getP_name()+"---"+person.getAge());

        return "Success, Person Id:" + person.getPerson_id();
    }

    @RequestMapping(value = "/hello", method = RequestMethod.GET)
    public String hello(){
        return "Hello Spring Cloud - Feign";
    }


}
